package com.atguigu.guli.service.cms.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.cms.entity.Ad;
import com.atguigu.guli.service.cms.service.AdService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 广告推荐 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-06-01
 */
@RestController

@RequestMapping("/admin/cms/ad")
public class AdminAdController {
    @Autowired
    AdService adService;
    //1、分页查询广告列表
    @GetMapping("list/{pageNum}/{pageSize}")
    public R list(@PathVariable Integer pageNum , @PathVariable Integer pageSize){
        Page<Ad> page = adService.page(new Page<>(pageNum, pageSize));
        return R.ok().setData("page" , page);
    }
    //2、新增广告
    @PostMapping("save")
    public R saveAd(@RequestBody Ad ad){
        adService.save(ad);
        return R.ok();
    }
    //3、查询指定广告
    @GetMapping("getById/{id}")
    public R getById(@PathVariable String id){
        Ad ad = adService.getById(id);
        return R.ok().setData("item" , ad);
    }
    //4、修改广告
    @PutMapping("update")
    public R update(@RequestBody Ad ad){
        adService.updateById(ad);
        return R.ok();
    }
    //5、删除广告
    @DeleteMapping("delete/{id}")
    public R deleteById(@PathVariable String id){
        adService.removeById(id);
        return R.ok();
    }
}

